package com.kma.summer2012.client;

import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionModel;
import com.google.gwt.view.client.SingleSelectionModel;
import com.kma.summer2012.client.Autorisation.Authorisation;
import com.kma.summer2012.client.ui.UserInfo;
import com.kma.summer2012.shared.model.UICrumbsUser;

import java.util.List;

public class MainModule implements EntryPoint {
    public void onModuleLoad() {

         /*
        AbsolutePanel panel = new AbsolutePanel();
        final CellTable<UICrumbsUser> userCellTable = new CellTable<UICrumbsUser>();
        final UserInfo userInfo = new UserInfo();

        Column<UICrumbsUser, String> nameColumn = new Column<UICrumbsUser, String>(new TextCell()) {
            @Override
            public String getValue(UICrumbsUser object) {
                return object.getSurnmNmSecondnm();
            }
        };
        nameColumn.setSortable(true);

        Column<UICrumbsUser, String> passwordColumn = new Column<UICrumbsUser, String>(new TextCell()) {
            @Override
            public String getValue(UICrumbsUser object) {
                return object.getPassword();
            }
        };

        userCellTable.addColumn(nameColumn, "Name");
        userCellTable.addColumn(passwordColumn, "Password");


        SelectionModel<UICrumbsUser> selectionModel = new SingleSelectionModel<UICrumbsUser>();

        selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
            public void onSelectionChange(SelectionChangeEvent event) {
                UICrumbsUser selectedUser = (UICrumbsUser) ((SingleSelectionModel) event.getSource()).getSelectedObject();
                userInfo.setName(selectedUser.getSurnmNmSecondnm());
                userInfo.setPassword(selectedUser.getPassword());
            }
        });

        userCellTable.setSelectionModel(selectionModel);

        CrumbsUserService.App.getInstance().getAllUsers(new AsyncCallback<List<UICrumbsUser>>() {
            public void onFailure(Throwable caught) {
                Window.alert(caught.getMessage());

            }

            public void onSuccess(List<UICrumbsUser> result) {
                ListDataProvider<UICrumbsUser> data = new ListDataProvider<UICrumbsUser>(result);
                data.addDataDisplay(userCellTable);
            }
        });

        panel.add(userCellTable);
        panel.add(userInfo);

        RootPanel.get("main").add(panel);   */
        /*AbsolutePanel panel = new AbsolutePanel();
        final AuthorisationTest authorisation = new AuthorisationTest();
        authorisation.setLoginText("Login:");
        authorisation.setPasswordText("Password:");
        panel.add(authorisation);
        RootPanel.get("main").add(panel);  */
        //AbsolutePanel panel = new AbsolutePanel();
        final Authorisation authorisation = new Authorisation();

        //panel.add(authorisation);
        //RootPanel.get("main").add(panel);
    }
}
